/*
 * <vadsl_common: 虚拟ADSL Linux Toolset 日志记录功能>
 * Copyright (C) 2012  张敬强 godfrey.public@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include "vadsl_common.h"

void time_print(FILE *stream, char *str){
	time_t time_std;
	struct tm *time_str;

	time(&time_std);
	time_str = localtime(&time_std);
	fprintf(stream, "%s%.2d时%.2d分%.2d秒\n", str, time_str->tm_hour, time_str->tm_min, time_str->tm_sec);
}

void name_print(FILE *stream){
	time_t time_std;
	struct tm *time_str;

	time(&time_std);
	time_str = localtime(&time_std);

	fprintf(stream, "%.2d-%.2d-%.2d:%s: ", time_str->tm_hour, time_str->tm_min, time_str->tm_sec, p_name);
}

void error_print_nolock(char *str, bool use_errno){
	name_print(stderr);
	fprintf(stderr, "ERROR:");
	if(use_errno)
		perror(str);
	else
		fprintf(stderr, "%s\n",str);
	fflush(stderr);
}

void info_print_nolock(char *str){
	name_print(stderr);
	fprintf(stderr, "INFO:%s\n",str);
	fflush(stderr);
}
